package leetcode.code384;

import java.util.Arrays;

import leetcode.helper.HelpDebug;

public class Solution extends Solution384 {

	private int[] nums;
	private int[] temp;

	public Solution(int[] nums) {
		this.nums = nums;
		this.temp = Arrays.copyOf(nums, nums.length);
	}

	/** Resets the array to its original configuration and return it. */
	public int[] reset() {
		return this.nums;
	}

	/** Returns a random shuffling of the array. */
	public int[] shuffle() {
		int len = nums.length;
		while (len > 0) {
			int random = (int) (Math.random() * len);
			int num = temp[len - 1];
			temp[len - 1] = temp[random];
			temp[random] = num;
			len--;
		}
		return temp;
	}

	public static void main(String[] args) {
		Solution so = new Solution(new int[] { 1, 2, 3 });
		for (int i = 0; i < 10; i++) {
			HelpDebug.printObject(so.shuffle());
			HelpDebug.printObject(so.reset());
			System.out.println("=========");
		}
	}
}
